package com.lbw.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name = (String) request.getParameter("name");
        String passwd = (String) request.getParameter("passwd");
        if ("admin".equals(name) && "123456".equals(passwd)) {
            request.setAttribute("name", name);
            request.getRequestDispatcher("ch3/success.jsp").forward(request, response);
        } else {
            response.sendRedirect(request.getContextPath() + "/ch3/login.html");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
